package com.qs.eggs.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.qs.eggs.R;
import com.qs.eggs.bean.Fenlei_item;

import java.util.ArrayList;

public class CategoryFirstMenuAdapter extends BaseAdapter {

	private ArrayList<Fenlei_item> arrarytotol=new ArrayList<Fenlei_item>();
	private Context context;
	private LayoutInflater inflate;

	private int clickTemp = 0;

	// 标识选择的Item
	public void setSeclect(int position) {
		this.clickTemp = position;
	}

	public CategoryFirstMenuAdapter(Context context, ArrayList<Fenlei_item> arrarytotol) {
		this.context = context;
		this.arrarytotol= arrarytotol;

	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return arrarytotol.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return arrarytotol.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub

		MyHodle mMyHodle = new MyHodle();

		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(
					R.layout.item_category_firstmenu, null);

			mMyHodle.textview = (TextView) convertView
					.findViewById(R.id.item_text_gridview);
			mMyHodle.textView_red = (TextView) convertView
					.findViewById(R.id.item_text_red);

			convertView.setTag(mMyHodle);
		}
		mMyHodle = (MyHodle) convertView.getTag();
		
		if (clickTemp == position) {
			mMyHodle.textView_red.setBackgroundColor(0Xffff0000);
			mMyHodle.textview.setTextColor(0Xffff0000);
			mMyHodle.textview.setBackgroundColor(0Xffffffff);


		} else {

			mMyHodle.textView_red.setBackgroundColor(0Xffffffff);
			mMyHodle.textview.setTextColor(0Xff808080);
			mMyHodle.textview.setBackgroundColor(0X808080);


		}

		mMyHodle.textview.setText(arrarytotol.get(position).getName());

		return convertView;
	}

	public class MyHodle {

		private TextView textview, textView_red;

	}

}
